#!/bin/bash
#========================================================================
# Author: YSLin
# Email: 
# File Name: getopts.sh
# Description: 
#   
# Edit History: 
#   2011-04-13    File created.
#========================================================================
NO_ARGS=0
E_OPTERROR=65
USAGE="Usage: `basename $0` -f<INFILE> -o<OUTFILE>
Try './`basename $0` -h' for more information."

if [ $# -eq "$NO_ARGS" ] # should check for no arguments
then
	exit $E_OPTERROR
fi

while getopts f:o:v:h OPTION ; do
	case "$OPTION" in
		f) 
			INFILE="$OPTARG" ;
			echo "input: $INFILE";;
		o) 
			OUTFILE="$OPTARG" ;
			echo "output: $OUTFILE";;
		v) 
			VERBOSE=true ;;
		h) echo "$USAGE" ;
			exit 1
			;;
	esac
done
#實際傳進的參數量
shift `echo "$OPTIND - 1" | bc` 
echo "$(($OPTIND - 1))"
# 做($OPTIND - 1)次的移位(shift)之後，就可以參照到
# 非選項之引數的其它引數
shift `expr $OPTIND - 1`
echo "other args: $*"
